<?php
/**
 * Encryption
 * @filesource
 */
/**
 * Namespace
 */
namespace framework\helper;
/**
 * Dependencies
 */
/**
 * Encryption Class
 * 
 * @author Randy Casburn <randy@plurious.com>
 * @copyright Copyright Plurious Software, all rights reserved
 * @license MIT
 * @license http://www.opensource.org/licenses/mit-license.html
 * @link http://plurious.com/framework/documentation/classes/Front.html
 * @version 2.1
 */
class Encryption {

    /** The encryption key */
    private $key;
    /**
     * Makes encryption available
     * @param string $key Use a large random string
     */
    function __construct($key = null) {
        $this->key = $key;
    }
    /**
     * Uses mcrypt to create a secure cipher of the input string that can be reversed.
     * 
     * @param string $value A Clear Text string
     * @return string An encrypted String
     */
    function encrypt($value) {
        $encrypted = bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->key), $string, MCRYPT_MODE_CBC, md5(md5($this->key))));        
        return $encrypted;
    }
    /**
     * Uses mcrypt to decipher the input string.
     * 
     * The input string was presumably ciphered with this class.
     * 
     * @param string $value An encrypted String
     * @return string A Clear Text string
     */
    function decrypt($value) {
        $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this->key), bin2hex($value), MCRYPT_MODE_CBC, md5(md5($this->key))), "\0"); 
        return $decrypted;
    }
}

?>